package rdd

import org.apache.spark.{SparkConf, SparkContext}

object RDD_DemoExample01 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("RDD_DemoExample01")

    val sc: SparkContext = new SparkContext(conf)
    val result: Array[String] = sc
      .textFile("data/employee.csv")
      .filter(line => !line.startsWith("ename,title"))
      .map(line => line.split(","))
      .sortBy(arr => {
        if (arr(6).trim.isEmpty)
          0.0
        else
          arr(6).toDouble
      }, false)
      .map(arr => arr.mkString(","))
      .take(3)

    result.foreach(println)




    sc.stop()
  }
}
